package com.app.common.dataDictionary.PO;

import java.util.BitSet;
import java.util.HashMap;
import java.util.Map;

import com.app.common.dataDictionary.DE.DE_DH_MONTH;
import com.app.common.dataDictionary.DE.DE_OPPTIME;
import com.app.common.dataDictionary.DE.DE_USERID;
import com.app.common.dataDictionary.DE.DE_W_PRIZE_CATEGORY;
import com.app.common.dataDictionary.DE.DE_W_PRIZE_ID;
import com.css.sword.kernel.base.annotation.PersistObject;
import com.css.sword.kernel.base.dataElement.AbsPersistObject;
import com.css.sword.kernel.base.dataElement.BaseDataElement;
import com.css.sword.kernel.base.dataElement.DateDE;
import com.css.sword.kernel.base.exception.SwordBaseCheckedException;


/**
 * 月份兑换数据维护表; InnoDB free: 10240 kB
 */
@PersistObject
public class TMonthdhdataMaintainPO extends AbsPersistObject {
	//private static final long serialVersionUID = 3114005081952019651L;
	private static final long serialVersionUID = 1L;
	private static final BitSet HAS_DEFAULT_VALUE = new BitSet(5);
	
	static{
	}
	
	/**
	 * 物理表名
	 */
	public static final String TABLE_NAME = "t_monthdhdata_maintain";

	/**
	 * 用户id
	 */
	private DE_USERID userid = DE_USERID.getTemplateInstance();

	/**
	 * 财富奖区奖品id
	 */
	private DE_W_PRIZE_ID wPrizeId = DE_W_PRIZE_ID.getTemplateInstance();

	/**
	 * 财富奖区奖品类别
	 */
	private DE_W_PRIZE_CATEGORY wPrizeCategory = DE_W_PRIZE_CATEGORY.getTemplateInstance();

	/**
	 * 兑换的月份
	 */
	private DE_DH_MONTH dhMonth = DE_DH_MONTH.getTemplateInstance();

	/**
	 * 操作时间
	 */
	private DE_OPPTIME opptime = DE_OPPTIME.getTemplateInstance();


	public TMonthdhdataMaintainPO(){
		this.insertState = new BitSet(5);
		this.updateState = new BitSet(5);
	}

	
	/**
	 * 获取 "用户id" 值
	 */	
	public DE_USERID getUserid(){
		return  userid;
	}
	
	/**
	 * 设置 "用户id" 值
	 */
	public void setUserid(DE_USERID userid) {
		if(userid == null){
			userid= DE_USERID.getTemplateInstance();
		}
		recordChangeFlag(0);
		this.userid = userid;
	}
	
	/**
	 * 获取 "财富奖区奖品id" 值
	 */	
	public DE_W_PRIZE_ID getWPrizeId(){
		return  wPrizeId;
	}
	
	/**
	 * 设置 "财富奖区奖品id" 值
	 */
	public void setWPrizeId(DE_W_PRIZE_ID wPrizeId) {
		if(wPrizeId == null){
			wPrizeId= DE_W_PRIZE_ID.getTemplateInstance();
		}
		recordChangeFlag(1);
		this.wPrizeId = wPrizeId;
	}
	
	/**
	 * 获取 "财富奖区奖品类别" 值
	 */	
	public DE_W_PRIZE_CATEGORY getWPrizeCategory(){
		return  wPrizeCategory;
	}
	
	/**
	 * 设置 "财富奖区奖品类别" 值
	 */
	public void setWPrizeCategory(DE_W_PRIZE_CATEGORY wPrizeCategory) {
		if(wPrizeCategory == null){
			wPrizeCategory= DE_W_PRIZE_CATEGORY.getTemplateInstance();
		}
		recordChangeFlag(2);
		this.wPrizeCategory = wPrizeCategory;
	}
	
	/**
	 * 获取 "兑换的月份" 值
	 */	
	public DE_DH_MONTH getDhMonth(){
		return  dhMonth;
	}
	
	/**
	 * 设置 "兑换的月份" 值
	 */
	public void setDhMonth(DE_DH_MONTH dhMonth) {
		if(dhMonth == null){
			dhMonth= DE_DH_MONTH.getTemplateInstance();
		}
		recordChangeFlag(3);
		this.dhMonth = dhMonth;
	}
	
	/**
	 * 获取 "操作时间" 值
	 */	
	public DE_OPPTIME getOpptime(){
		return  opptime;
	}
	
	/**
	 * 设置 "操作时间" 值
	 */
	public void setOpptime(DE_OPPTIME opptime) {
		if(opptime == null){
			opptime= DE_OPPTIME.getTemplateInstance();
		}
		recordChangeFlag(4);
		this.opptime = opptime;
	}


	@Override
	public BaseDataElement<?>[] fields(){
		return new BaseDataElement<?>[] {userid,wPrizeId,wPrizeCategory,dhMonth,opptime};
	}
	
	@Override
	public String[] fieldNames() {
		return new String[]{"userid","wPrizeId","wPrizeCategory","dhMonth","opptime"};
	}
	
	@Override
	public BaseDataElement<?> getFieldValue(String fieldName)  {
		if ("userid".equals(fieldName)) {
			return userid;
		}
		if ("wPrizeId".equals(fieldName)) {
			return wPrizeId;
		}
		if ("wPrizeCategory".equals(fieldName)) {
			return wPrizeCategory;
		}
		if ("dhMonth".equals(fieldName)) {
			return dhMonth;
		}
		if ("opptime".equals(fieldName)) {
			return opptime;
		}
 
		throw new IllegalArgumentException("PO对象中没有"+fieldName+"字段");
	}
	
	@Override
	public TMonthdhdataMaintainPO setFieldValue(String fieldName, Object fieldValue) throws SwordBaseCheckedException {
		if (fieldValue != null && !(fieldValue instanceof BaseDataElement<?>)) {
			throw new SwordBaseCheckedException("字段值类型不是DataElelement子类型");
		}

		if ("userid".equals(fieldName)) {
			if (fieldValue == null) {
				setUserid(null);
			} else {
				setUserid((DE_USERID) fieldValue);
			}
			return this;
		}

		if ("wPrizeId".equals(fieldName)) {
			if (fieldValue == null) {
				setWPrizeId(null);
			} else {
				setWPrizeId((DE_W_PRIZE_ID) fieldValue);
			}
			return this;
		}

		if ("wPrizeCategory".equals(fieldName)) {
			if (fieldValue == null) {
				setWPrizeCategory(null);
			} else {
				setWPrizeCategory((DE_W_PRIZE_CATEGORY) fieldValue);
			}
			return this;
		}

		if ("dhMonth".equals(fieldName)) {
			if (fieldValue == null) {
				setDhMonth(null);
			} else {
				setDhMonth((DE_DH_MONTH) fieldValue);
			}
			return this;
		}

		if ("opptime".equals(fieldName)) {
			if (fieldValue == null) {
				setOpptime(null);
			} else {
				setOpptime((DE_OPPTIME) fieldValue);
			}
			return this;
		}

		throw new SwordBaseCheckedException("PO对象中没有"+fieldName+"字段");
	}

	@Override
	protected TMonthdhdataMaintainPO clone() {
		TMonthdhdataMaintainPO t = new TMonthdhdataMaintainPO();
		
		t.setUserid(this.userid);
		t.setWPrizeId(this.wPrizeId);
		t.setWPrizeCategory(this.wPrizeCategory);
		t.setDhMonth(this.dhMonth);
		t.setOpptime(this.opptime);

		return t;
	}

	@Override
	public TMonthdhdataMaintainPO loadMap(Map<String, Object> dataMap) throws SwordBaseCheckedException {
		Object value = null;

		if(dataMap.containsKey("userid")){
			value = dataMap.get("userid");
			
			if (value == null) {
				this.setUserid(null);
			} else {
				if (value instanceof DE_USERID) {
					this.setUserid((DE_USERID) value);
				}
			    else {
					this.setUserid(new DE_USERID(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("wPrizeId")){
			value = dataMap.get("wPrizeId");
			
			if (value == null) {
				this.setWPrizeId(null);
			} else {
				if (value instanceof DE_W_PRIZE_ID) {
					this.setWPrizeId((DE_W_PRIZE_ID) value);
				}
			    else {
					this.setWPrizeId(new DE_W_PRIZE_ID(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("wPrizeCategory")){
			value = dataMap.get("wPrizeCategory");
			
			if (value == null) {
				this.setWPrizeCategory(null);
			} else {
				if (value instanceof DE_W_PRIZE_CATEGORY) {
					this.setWPrizeCategory((DE_W_PRIZE_CATEGORY) value);
				}
			    else {
					this.setWPrizeCategory(new DE_W_PRIZE_CATEGORY(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("dhMonth")){
			value = dataMap.get("dhMonth");
			
			if (value == null) {
				this.setDhMonth(null);
			} else {
				if (value instanceof DE_DH_MONTH) {
					this.setDhMonth((DE_DH_MONTH) value);
				}
			    else {
					this.setDhMonth(new DE_DH_MONTH(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("opptime")){
			value = dataMap.get("opptime");
			
			if (value == null) {
				this.setOpptime(null);
			} else {
				if (value instanceof DE_OPPTIME) {
					this.setOpptime((DE_OPPTIME) value);
				}
				else if(value instanceof java.util.Date){
					this.setOpptime(new DE_OPPTIME((java.util.Date)value));
				}
			    else {
					this.setOpptime(new DE_OPPTIME(value.toString()));
				}
			}
		}

		return this;
	}
	
	@Override
	public Map<String,Object> toMap() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("userid", userid);
		dataMap.put("wPrizeId", wPrizeId);
		dataMap.put("wPrizeCategory", wPrizeCategory);
		dataMap.put("dhMonth", dhMonth);
		dataMap.put("opptime", opptime);
		
		return dataMap;
	}
	
	@Override
	public Map<String,Object> toMapWithDEValue() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("userid", (userid==null?null:userid.value));
		dataMap.put("wPrizeId", (wPrizeId==null?null:wPrizeId.value));
		dataMap.put("wPrizeCategory", (wPrizeCategory==null?null:wPrizeCategory.value));
		dataMap.put("dhMonth", (dhMonth==null?null:dhMonth.value));
		dataMap.put("opptime", (opptime==null?null:opptime.value));
		
		return dataMap;
	}
	
	@Override
	public TMonthdhdataMaintainPO newInstance() {
		return new TMonthdhdataMaintainPO();
	}
	
	@Override
	public String getTableName(){
		return TABLE_NAME;
	}
	
	@Override
	public BaseDataElement<?>[] getPrimaryKey() {
		return new BaseDataElement<?>[]{userid,wPrizeId,wPrizeCategory};
	}

	@Override
	public void checkNotNull(byte sqlType) throws SwordBaseCheckedException {
		StringBuilder errorMsg = new StringBuilder();
		// insert
		if (sqlType == 0) {
				//只校验不可为空但又没有默认值的字段
				if (userid.value == null && !HAS_DEFAULT_VALUE.get(0)) {
					errorMsg.append("字段userid不允许为空\n");
				}
				if (wPrizeId.value == null && !HAS_DEFAULT_VALUE.get(1)) {
					errorMsg.append("字段wPrizeId不允许为空\n");
				}
				if (wPrizeCategory.value == null && !HAS_DEFAULT_VALUE.get(2)) {
					errorMsg.append("字段wPrizeCategory不允许为空\n");
				}
				if (dhMonth.value == null && !HAS_DEFAULT_VALUE.get(3)) {
					errorMsg.append("字段dhMonth不允许为空\n");
				}

		}
		// update
		else if (sqlType == 1) {
		if (updateState.get(0) && userid.value == null) {
			errorMsg.append("字段userid不允许为空\n");
		}
		if (updateState.get(1) && wPrizeId.value == null) {
			errorMsg.append("字段wPrizeId不允许为空\n");
		}
		if (updateState.get(2) && wPrizeCategory.value == null) {
			errorMsg.append("字段wPrizeCategory不允许为空\n");
		}
		if (updateState.get(3) && dhMonth.value == null) {
			errorMsg.append("字段dhMonth不允许为空\n");
		}

		}
		
		if (errorMsg.length() > 0) {
			errorMsg.setLength(errorMsg.length() - 1);
			throw new SwordBaseCheckedException(errorMsg.toString());
		}
	}

	@Override
	public void updateLrrq(DateDE lrrq) {
	}

	@Override
	public void updateXgrq(DateDE xgrq) {
	}

	@Override
	public String toString() {
		StringBuilder str = new StringBuilder();
		str.append("userid:").append(userid.value!=null?userid:"").append(" ").append("wPrizeId:").append(wPrizeId.value!=null?wPrizeId:"").append(" ").append("wPrizeCategory:").append(wPrizeCategory.value!=null?wPrizeCategory:"").append(" ").append("dhMonth:").append(dhMonth.value!=null?dhMonth:"").append(" ").append("opptime:").append(opptime.value!=null?opptime:"").append(" ");
		return str.toString();
	}
	
}
